<?php

include '../model/db.php';
include '../model/fn.php';

if($_POST['submit']=='确定')
{
    $arr=array();
    $arr['title']=$_POST['title'];
    $arr['cid']=$_POST['cid'];
    $arr['user']=$_POST['user'];
    $arr['tj']=$_POST['tj'];
    $arr['msg']=$_POST['msg'];
    $arr['txt']=htmlspecialchars($_POST['editorValue']);

    if($_FILES['img']){
        //调用公共方法完成上传
        $arr['img']=upd_file($_FILES['img'],'/public/admin/wz');

        $arr['ximg']=getPic($arr['img']);

    }
    $arr['time']=time();
    $arr['ydl']=0;
    //修改数据库
    $id=db_upd('bl_wz',$arr,' id='.$_GET['id']);
    if($id){
        exit("<script>alert('操作成功！');location.href='./goodslist.php';</script>");
    }else{
        exit("<script>alert('操作失败！');location.href='./goodsadd.php';</script>");
    }
}
//查询所有分类
$sql="select * from bl_class";
$arr=db_sel($sql,2); //查询所有

//无限极排序---递归实现
$list=fl($arr);

$sql="select * from bl_wz where id = '{$_GET['id']}'";
$wzarr=db_sel($sql);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>后台 管理中心 - 添加新文章 </title>
    <meta name="robots" content="noindex, nofollow">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <link href="../public/admin/styles/general.css" rel="stylesheet" type="text/css" />
    <link href="../public/admin/styles/main.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript" charset="UTF-8" src="../public/admin/ueditor/ueditor.config.js"></script>
    <script type="text/javascript" charset="UTF-8" src="../public/admin/ueditor/ueditor.all.min.js"></script>
</head>
<body>

<h1>
    <span class="action-span"><a href="goodslist.php?act=list">文章列表</a></span>
    <span class="action-span1"><a href="index.php?act=main">后台 管理中心</a> </span><span id="search_id" class="action-span1"> - 添加新文章 </span>
    <div style="clear:both"></div>
</h1>

<!-- start goods form -->
<div class="tab-div">
    <!-- tab bar -->
    <div id="tabbar-div">
        <p>
            <span class="tab-front" id="general-tab">添加文章</span>
        </p>
    </div>

    <!-- tab body -->
    <div id="tabbody-div">
        <form enctype="multipart/form-data" action="./goodsupd.php?id=<?php echo $wzarr['id']?>" method="post" name="theForm" >

            <table width="90%" id="general-table" align="center">
                <tr>
                    <td class="label">文章标题：</td>
                    <td><input type="text" name="title" value="<?php echo $wzarr['title']?>" style="float:left;color:;" size="30" /></td>
                </tr>

                <tr>
                    <td class="label">文章分类：</td>
                    <td>
                        <select name="cid"  >
                            <?php foreach($list as $v){?>
                                <option <?php if($v['id']==$wzarr['cid']){echo 'selected';}?> value="<?php echo $v['id']?>">
                                    <?php if($v['pid']!=0){echo '&nbsp;&nbsp;&nbsp;&nbsp;';}echo $v['name']?>
                                </option>
                            <?php }?>
                        </select>
                    </td>
                </tr>
                <tr>
                    <td class="label">作者：</td>
                    <td><input type="text" name="user" value="<?php echo $wzarr['user']?>" size="20" /></td>
                </tr>

                <tr>
                    <td class="label">上传文章图片：</td>
                    <td>
                        <input type="file" name="img" size="35" />
                        <img src="<?php echo $wzarr['img']?>" alt="没有图片">
                    </td>
                </tr>
                <tr>
                    <td class="label">是否推荐：</td>
                    <td>
                        是：<input type="radio" name="tj" <?php if($wzarr['tj']=='1'){echo 'checked';}?> value="1" size="35" />
                        否：<input type="radio" name="tj" <?php if($wzarr['tj']=='2'){echo 'checked';}?> value="2" size="35" />
                    </td>
                </tr>

                <tr>
                    <td class="label">文章描述：</td>
                    <td>
                        <textarea name="msg" rows="" cols=""><?php echo $wzarr['msg']?></textarea>
                    </td>
                </tr>
                <tr>
                    <td class="label">文章内容：</td>
                    <td>
                        <script id="editor" type="text/plain" style="width:800px;height:300px;">
                            <?php echo htmlspecialchars_decode($wzarr['txt'])?>
                    </script>
                    </td>
                </tr>

            </table>
            <div class="button-div">
                <input type="submit" value="确定" name="submit" class="button" />
                <input type="reset" value=" 重置 " class="button" />
            </div>
        </form>
    </div>
</div>
<!-- end goods form -->
<script>
    var ue=UE.getEditor('editor');
    //    function getContent(){
    //        UE.getEditor('editor').getContent();
    //    }
    //    function abc(){
    //        var txt=UE.getEditor('editor').getContent();
    //        var obj=document.getElementById('txt');
    //        obj.value=txt;
    //    }
</script>
</body>
</html>